//
// Created by win10 on 2024/12/31.
//
#include <stdio.h>
void printArray(int arr[], int size) {
    for (int i = 0; i < size; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");
}
int main() {
    int n;
    scanf("%d",&n);
    int arr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    for (int i = 0; i < n-1; i++) {
        int minIndex = i;
        for (int j = i+1; j < n; j++) {
            if (arr[i] > arr[j]) {
                minIndex = j;
            }
        }
        if (minIndex != i) {
            if (minIndex!= i) {
                int temp = arr[i];
                arr[i] = arr[minIndex];
                arr[minIndex] = temp;
            }
        }
        if (i == n - 1) {
            printf("sorted array: ");
        } else {
            printf("step %d: ", i + 1);
        }
        printArray(arr, n);
    }
}